<?php


require_once "epay_core.function.php";
require_once "epay_md5.function.php";
class AlipayNotify
{
	public $alipay_config;
	public function __construct($alipay_config)
	{
		$this->alipay_config = $alipay_config;
		$this->http_verify_url = $this->alipay_config["apiurl"] . "api.php?";
	}
	public function AlipayNotify($alipay_config)
	{
		$this->__construct($alipay_config);
	}
	public function verifyNotify()
	{
		if (empty($_GET)) {
			return false;
		} else {
			$isSign = $this->getSignVeryfy($_GET, $_GET["sign"]);
			$responseTxt = "true";
			if (preg_match("/true\$/i", $responseTxt) && $isSign) {
				return true;
			} else {
				return false;
			}
		}
	}
	public function verifyReturn()
	{
		if (empty($_GET)) {
			return false;
		} else {
			$isSign = $this->getSignVeryfy($_GET, $_GET["sign"]);
			$responseTxt = "true";
			if (preg_match("/true\$/i", $responseTxt) && $isSign) {
				return true;
			} else {
				return false;
			}
		}
	}
	public function getSignVeryfy($para_temp, $sign)
	{
		$para_filter = paraFilter($para_temp);
		$para_sort = argSort($para_filter);
		$prestr = createLinkstring($para_sort);
		$isSgin = false;
		$isSgin = md5Verify($prestr, $sign, $this->alipay_config["key"]);
		return $isSgin;
	}
	public function getResponse($trade_no)
	{
		$partner = trim($this->alipay_config["partner"]);
		$veryfy_url = $this->http_verify_url . "act=order&pid=" . $partner . "&trade_no=" . $trade_no;
		$responseTxt = getHttpResponseGET($veryfy_url);
		$arr = json_encode($responseTxt, true);
		if ($arr["status"] == 1) {
			return "true";
		} else {
			return "false";
		}
	}
}